import {
  Button,
  Text,
  AppRegistry,
  StyleSheet,
  Dimensions,
  View,
  SafeAreaView,
  ScrollView,
} from 'react-native';
import React, {Component} from 'react';
import WebView from 'react-native-webview';

import test from './dist1/test';

//获取设备的宽度和高度
let {height: deviceHeight, width: deviceWidth} = Dimensions.get('window');

// import test from "./test.js";
// const test = `function injectedScript() {
//   console.log('666')
//   console.log(666)
// }
// injectedScript();`;
// const test = `
//   console.log('666')
//   console.log(666)`;

let injectedJavaScript = `
    console.log(123)
    window.ReactNativeWebView.postMessage('Hello RN!')
  `;
function WebviewScreen({navigation, route}) {
  console.log(666);
  console.log(route);

  // webview地址
  // const url = route?.params?.url || ''
  const url = 'file:///android_asset/web/dist/index.html';
  // const url = 'http://192.168.110.168:8000/v3Test/home'

  console.log('url');
  console.log(url);

  //获取设备的宽度和高度
  // var {height: deviceHeight, width: deviceWidth} = Dimensions.get('window');
  // console.log(deviceHeight);
  // console.log(deviceWidth);

  // const webviewRef = useRef(null);

  let onWebViewMessage = event => {
    // alert('收到消息:', event.nativeEvent.data);
    console.log(event.nativeEvent.data);
    // const data = event?.nativeEvent?.data;
    // // 解析jsbridge消息
    // transfer(data, (res) => {
    //     console.log('message:res');
    //     console.log(res);
    //     sendMessageToHtml(res);
    // });
  };


  //样式定义
  const styles = StyleSheet.create({
    container: {
      flex: 1,
    },
  });
  return (
    <SafeAreaView style={styles.container}>
      <WebView
        bounces={true}
        scalesPageToFit={true}
        source={require('./dist1/index.html')}
        injectedJavaScript={test}
        onMessage={onWebViewMessage}></WebView>
    </SafeAreaView>
  );
}

export default WebviewScreen;
